#ifndef AVALON_HTTPCLIENTCHANNEL_HPP
#define AVALON_HTTPCLIENTCHANNEL_HPP
#include "Avalon/IO/Buffer.hpp"
#include "Avalon/IO/Channel.hpp"
#include "Avalon/IO/ConnectionState.hpp"
#include "Avalon/WebServices/HttpRequestParser.hpp"
#include "Avalon/WebServices/WebServices.hpp"

namespace Avalon {
namespace WebServices {

  /*! \class HttpClientChannel
   *  \brief Encapsulates a Channel used by the HttpServer.
   *  \author Kamal Mansouri <kranar@hotmail.com>
   */
  class HttpClientChannel : public IO::Channel {
    public:

      //! Constructs an HttpClientChannel.
      /*!
        \param channel The existing Channel to the client.
      */
      HttpClientChannel(IO::Channel* channel);

      virtual ~HttpClientChannel();

      //! Returns the Channel's ConnectionState.
      IO::ConnectionState& GetChannelState();

      //! Returns the flag indicating whether a read operation is pending.
      bool IsReadPending();

      //! Sets the read state.
      void SetReadPending(bool value);

      //! Returns the HttpRequestParser for this Channel.
      HttpRequestParser& GetHttpRequestParser();

      //! Returns the Buffer used in the current read operation.
      IO::Buffer& GetReadBuffer();

      virtual IO::Connection& GetConnection();

      virtual IO::Reader& GetReader();

      virtual IO::Writer& GetWriter();

    private:
      boost::scoped_ptr<IO::Channel> m_channel;
      IO::ConnectionState m_channelState;
      bool m_isReadPending;
      HttpRequestParser m_httpRequestParser;
      IO::Buffer m_readBuffer;
  };
}
}

#endif // AVALON_HTTPCLIENTCHANNEL_HPP
